<link href="<?php echo Yii::app()->request->baseUrl; ?>/css/styles.css" rel="stylesheet" media="screen"  />
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.js" ></script>
<script  type="text/javascript" language="javascript">
	$(document).ready(function(){
    $('.adCntnr div.acco2:eq(0)').find('div.expand:eq(0)').addClass('').end()
    	.find('div.collapse:eq(0)').hide().end()
    .find('div.collapse:gt(0)').hide().end()
    .find('div.expand').click(function() {
        $(this).toggleClass('openAd').siblings().removeClass('openAd').end()
        .next('div.collapse').slideToggle().siblings('div.collapse:visible').slideUp();
        return false;
    });
})
</script>
 
	<div class="quizbutton"><a data-icon="arrow-r" rel="external" href="<?php echo Yii::app()->request->urlReferrer ?>"  data-role="button" class="ui-btn-right" data-theme="e" ><?php echo "Go Back";?></a></div>
  

<?php 
if (isset($attemptDetails) && $attemptDetails)
{
	$user=Users::model()->getModel('USER-ID', array('userid'=>$attemptDetails->user_id));
	$quizdetails=Quiz::model()->getModel('QUIZ-ID', array('quizid'=>$attemptDetails->quiz_id));	
	//$chapterdetails=Chapter::model()->getModel('CHAPTER-ID',  array('chapterid'=>$attemptDetails->chapter_id));
	$userattemptdetails=UserQuizAttemptDetails::getList("ATTEMPT-ID",array('attemptid'=>$attemptDetails->id));
	$usercorrectattempts=UserQuizAttemptDetails::getList("ANSWER-STATUS",array('attemptid'=>$attemptDetails->id,'status'=>'correct'));
	
	$questiontotal=Quiz::getQuestionTotalPoints($attemptDetails->quiz_id,$attemptDetails->id);
	$percentageGained=($attemptDetails->total_points/$questiontotal)*100;
}
?>
<div class="bodywrap">
 
   <h2>Summary</h2>
  <div class="quizdetails">
    <ul>
      <li>
        <div class="leftdetail">Total Questions<span style="float:right">|</span> </div>
        <div class="rightdetail"><?php echo $attemptDetails->no_of_questions;?> </div>
      </li>
      <li>
        <div class="leftdetail">Questions Answered Correctly<span style="float:right">|</span> </div>
        <div class="rightdetail"><?php echo sizeof($usercorrectattempts);?> </div>
      </li>
      <li>
        <div class="leftdetail">Percentage Gained<span style="float:right">|</span> </div>
        <div class="rightdetail">
		<span style="color:#f00; font-weight:bold;"><?php echo (int)$percentageGained."%";?></span>
 </div>
      </li>
      <li>
        <div class="leftdetail">Result<span style="float:right">|</span> </div>
        <div class="rightdetail">
		<?php 
	if($attemptDetails->result=="fail")
	{
		echo "<span style='color:red'>F</span";
	}
	else
	echo "Pass";
?>
 </div>
      </li>
      
      <li>
        <div class="leftdetail">Total Points Scored:<span style="float:right">|</span> </div>
        <div class="rightdetail">
		<span style="color:#f00; font-weight:bold;"><?php if($attemptDetails->result=="pass")
	{?>
  <?php echo $attemptDetails->total_points;?><br/>
      <?php }?></span>
 </div>
      </li>
    </ul>
  </div>
  
  <br clear="all" />
  
  <!--<div style="background:#fbfbfb">
    <p><b style="font-weight:bold; color:black">Result:</b><span style="color:#930"> <?php 
	if($attemptDetails->result=="fail")
	{
		echo " Fail (You need to get <span style='color:green; font-weight:bold'>".$quizdetails->passing_percentage."%"."</span> to pass)";
	}
	else
	echo "Pass";
?></span><br/>

    
      <span style="color:#f00; font-weight:bold;">Percentage Gained: <?php echo (int)$percentageGained."%";?></span><br/>
     
      <?php if($attemptDetails->result=="pass")
	{?>
      Total Points Scored:<?php echo $attemptDetails->total_points;?><br/>
      <?php }?>
    </p>
  </div>-->
</div>

<h2>Attempt Details</h2>
<div style="width:100%; margin:0 auto 0 auto;">
   
  <div class="adCntnr" >
    <div class="acco2">
      <?php if ($userattemptdetails)
		{
		foreach($userattemptdetails as $attemptdetail)
		{
			$question=Questions::model()->getModel("QUESTION-ID", array('questionid'=>$attemptdetail->question_id));
			$option=Options::model()->getModel("OPTION-ID", array("optionid"=>$attemptdetail->option_id));
			$optionList=Options::getList("QUESTION-ID",array('questionid'=>$attemptdetail->question_id));
			$selectedoption="";
			$correctoption="";
			foreach ($optionList as $key=>$option1)
			{
				if (isset($option1->id) && isset($option->id) && $option1){
				if ($option1->id==$option->id)
				$selectedoption=$key+1;
				
				if ($option1->correct_option=="yes")
				{
					$correctoption=$key+1;
				}
				}
			}
			if ($selectedoption==$correctoption)
			{
				$image="tick.png";
			}
			else 
			{
				$image="wrong.png";
			}
			if ($attemptdetail->answer_status=="correct")
			{
				
				$image="tick.png";
				$correctoption=$selectedoption;
			}
			else 
			{
				$image="wrong.png";
			}
			
			?>
      <div class="expand"><a title="expand/collapse" href="#" style="display: block;">
        <div style="float:left; min-width:35%;"><?php echo $attemptdetail->order;?></div>
        <div style="float:left; min-width:35%; padding-top:1px;"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/<?php echo $image;?>" width="16px" height="16px"/><span style="float:right;">|</span></div>
        <div style="float:left; padding-left:8px ">Details</div>
        <br clear="all" />
        </a> </div>
      <div class="collapse">
        <div class="accCntnt">
          <div class="titlebarLeftc" style="border-bottom:1px solid #dadada;">
            <div class="titlebarRightc">
              <div class="titlebar">
                <table class="dataGridHdr" width="100%" cellpadding="0" cellspacing="0">
                  <tr>
                    <td class="dataGridHdr_boder" style="padding-left:0; font-weight:bold; color:#930";><?php echo $question->description;?><div style="clear:both"></div></td>
                  </tr>
                </table>
              </div>
            </div>
          </div>
          <div class="dataGrid_container">
            <table class="dataGrid" width="100%" cellpadding="0" cellspacing="0">
              <tr class="dataAlterRw1">
                <td class="dataGridHdr_boder"><div class="quiz">
                    <ul>
                      <?php 
			foreach ($optionList as $key=>$option1)
			{if (isset($option1->id) && isset($option->id) &&$option1){
				$num=$key+1;
				if ($option1->id==$option->id)
				{?>
                      <li><?php echo $num.")";?>&nbsp;
                          <label class="label_check" for="<?php echo $option1->id;?>">
                          <input name="sample-radio<?php echo $option1->id;?>" id="<?php echo $option1->id;?>" value="1" type="radio"  checked="checked" class="check" disabled/>
                          &nbsp;<?php echo $option1->name;?></label>
                          &nbsp;
                          <?php if($option1->correct_option == 'yes'){ ?>
                            <img src="<?php echo Yii::app()->request->baseUrl; ?>/images/tick.png" width="16px" height="16px"/>    
                          <?php } ?>
                      </li>
                      <?php }
				else 
				{?>
                      <li><?php echo $num.")";?>&nbsp;
                          <label class="label_check" for="<?php echo $option1->id;?>">
                          <input name="sample-radio<?php echo $option1->id;?>" id="<?php echo $option1->id;?>" value="1" type="radio" class="check" disabled/>
                          &nbsp;<?php echo $option1->name;?></label>
                          &nbsp;
                          <?php if($option1->correct_option == 'yes'){ ?>
                            <img src="<?php echo Yii::app()->request->baseUrl; ?>/images/tick.png" width="16px" height="16px"/>    
                          <?php } ?>
                      </li>
                      <?php }
			}
			}
    	
    	?>
                    </ul>
                  </div></td>
              </tr>
              <tr class="dataAlterRw2">
                <td class="dataGridHdr_boder" style="line-height:1.75em;"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/<?php echo $image;?>" width="16px" height="16px"/> <span style="color:#930; font-weight:bold;"> Explanation: </span><?php echo $question->correct_answer_desc;?></td>
              </tr>
            </table>
          </div>
        </div>
      </div>
     
      <?php 
			
				}	
				}
			?>
    </div>
  </div>
</div>